Completed
Pull Request — master (#77)
by Maxence
03:09
created

resultMembers.searchMembersResult   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.2
cc 4
nc 2
nop 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A 0 4 1
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
/** global: Notyf */
29
30
/** global: actions */
31
/** global: nav */
32
/** global: elements */
33
/** global: curr */
34
/** global: api */
35
36
37
var resultMembers = {
38
39
40
	searchMembersResult: function (response) {
41
42
		elements.membersSearchResult.children().remove();
43
44
		if (response === null ||
45
			(response.ocs.data.users.length === 0 && response.ocs.data.exact.users.length === 0)) {
46
			elements.membersSearchResult.fadeOut(0);
47
			return;
48
		}
49
50
		elements.fillMembersSearch(response.ocs.data.exact.users, response.ocs.data.users);
51
52
		$('.members_search').on('click', function () {
53
			api.addMember(curr.circle, $(this).attr('searchresult'),
54
				resultMembers.addMemberResult);
55
		});
56
		elements.membersSearchResult.fadeIn(300);
57
	},
58
59
60
	addMemberResult: function (result) {
61
62
		if (result.status === 1) {
63
			OCA.notification.onSuccess(
64
				t('circles', "Member '{name}' successfully added to the circle",
65
					{name: result.name}));
66
67
			nav.displayMembers(result.members);
68
			return;
69
		}
70
		OCA.notification.onFail(
71
			t('circles', "Member '{name}' could not be added to the circle", {name: result.name}) +
72
			': ' +
73
			((result.error) ? result.error : t('circles', 'no error message')));
74
	},
75
76
77
	removeMemberResult: function (result) {
78
		if (result.status === 1) {
79
80
			elements.rightPanel.fadeOut(300);
81
			elements.mainUIMembers.children("[member-id='" + result.name + "']").each(
82
				function () {
83
					$(this).hide(300);
84
				});
85
			OCA.notification.onSuccess(
86
				t('circles', "Member '{name}' successfully removed from the circle",
87
					{name: result.name}));
88
			return;
89
		}
90
91
		OCA.notification.onFail(
92
			t('circles', "Member '{name}' could not be removed from the circle",
93
				{name: result.name}) +
94
			': ' +
95
			((result.error) ? result.error : t('circles', 'no error message')));
96
	},
97
98
	levelMemberResult: function (result) {
99
		if (result.status === 1) {
100
			OCA.notification.onSuccess(
101
				t('circles', "Member '{name}' updated",
102
					{name: result.name}));
103
104
			nav.displayMembers(result.members);
105
			return;
106
		}
107
		OCA.notification.onFail(
108
			t('circles', "Member '{name}' could not be updated", {name: result.name}) +
109
			': ' +
110
			((result.error) ? result.error : t('circles', 'no error message')));
111
	},
112
113
114
};
115